import apiClient from '@/api/axios.js';

export class FollowRelationApi {

  // 查询所有关注关系
  static async getAllFollowRelations() {
    try {
      const response = await apiClient.get('/followrelation');
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 根据 followerID 和 followedID 查询关注关系
  static async getFollowRelationByUserIds(followerID, followedID) {
    try {
      const response = await apiClient.get(`/followrelation/follower/${followerID}/followed/${followedID}`);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 根据 followerID 查询关注关系
  static async getFollowRelationsByFollowerId(followerID) {
    try {
      const response = await apiClient.get(`/followrelation/follower/${followerID}`);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 根据 followedID 查询关注关系
  static async getFollowRelationsByFollowedId(followedID) {
    try {
      const response = await apiClient.get(`/followrelation/followed/${followedID}`);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 新增关注关系
  static async createFollowRelation(params) {
    const { followerID, followedID, createTime } = params;
    try {
      const response = await apiClient.post('/followrelation', {
        followerID,
        followedID,
        createTime
      });
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 更新关注关系
  static async updateFollowRelation(params) {
    const { followerID, followedID, createTime } = params;
    try {
      const response = await apiClient.put('/followrelation', {
        followerID,
        followedID,
        createTime
      });
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }

  // 删除关注关系
  static async deleteFollowRelation(followerID, followedID) {
    try {
      const response = await apiClient.delete(`/followrelation/follower/${followerID}/followed/${followedID}`);
      return response.data;
    } catch (error) {
      throw new Error(error.message);
    }
  }
}
